#pragma once

#include <iostream>
#include <cassert>
using namespace std;

class Date
{
public:
	Date(int year = 1900, int month = 1, int day = 1);
	void Print();

	bool isLeapYear(int year)
	{
		return (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
	}

	// 直接在类里面定义就是内联，默认就是inline
	int GetMonthDay(int year, int month)
	{
		assert(month > 0 && month < 13);
		static int monthDayArray[13] = { -1, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
		if (month == 2 && isLeapYear(year)) {
			return 29;
		}

		return monthDayArray[month];
	}

	bool operator<(const Date& d);
	bool operator<=(const Date& d);
	bool operator>(const Date& d);
	bool operator>=(const Date& d);
	bool operator!=(const Date& d);
	bool operator==(const Date& d);

	Date& operator+=(int day);
	Date operator+(int day);

	Date& operator-=(int day);
	Date operator-(int day);

	int operator-(const Date& d);

	// 前置++和后置++都是一元运算符，为了让前置++与后置++形成能正确重载
	// C++规定：后置++重载时多增加一个int类型的参数，但调用函数时该参数不用传递，编译器自动传递
	// 自定义类型尽量前置，效率高些
	Date& operator++();
	Date operator++(int);

	Date& operator--();
	Date operator--(int);

private:
	int _year;
	int _month;
	int _day;
};